Title: Setting up Python Virtual Environments

[vtoc]: #venvtoc "Section Contents" class=backref

# Setting up Python Virtual Environments [&#x21d1;][rtoc] [venvtoc]

* [Installing the virtualenv package][venvinstall]
* [Creating virtual environments][venvcreate]
* [Activating the virtual environment][venvact]
* [Deactivating the virtual environment][venvdeact]

This project delivers both a Python 2 and Python 3 release. It needs to be tested in multiple versions of Python. The best way to do that is to setup virtal Python environments that you can easily switch between. I like using `virtualenv` to do that.

I am assuming here that you have both Mac Ports python27 and python33 installed on your OS X system. If you use brew or fink or something similar, you can make the necessary adjustments in the location of the respective Python framework paths.

## Installing the virtualenv package [&#x21d1;][vtoc] [venvinstall]

To install virtualenv, use either:

```bash
$ sudo /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip install virtualenv
$ sudo /opt/local/Library/Frameworks/Python.framework/Versions/3.3/bin/pip install virtualenv
```

or

```bash
$ sudo /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install install virtualenv
$ sudo /opt/local/Library/Frameworks/Python.framework/Versions/3.3/bin/easy_install install virtualenv
```

## Creating virtual environments [&#x21d1;][vtoc] [venvcreate]

### Setting up a Python 2.7 virtual environment

```bash
$ cd myproject
$ /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv venv27
```

### Setting up a Python 3.3 virtual environment

```bash
$ cd myproject
$ /opt/local/Library/Frameworks/Python.framework/Versions/3.3/bin/virtualenv venv33
```

## Activating the virtual environment [&#x21d1;][vtoc] [venvact]

### Activating the Python 2.7 virtual environment

```bash
$ cd myproject
$ . venv27/bin/activate
(venv27)$ python --version
Python 2.7.6
(venv27)$
```

### Activating the Python 3.3 virtual environment

```bash
$ cd myproject
$ . venv33/bin/activate
(venv33)$ python --version
Python 3.3.4
(venv33)$
```

## Deactivating the virtual environment [&#x21d1;][vtoc] [venvdeact]

### Deactivating the Python 2.7 virtual environment

```bash
(venv27)$ deactivate
$ python --version
Python 2.7.5
$
```

### Deactivating the Python 3.3 virtual environment

```bash
(venv33)$ deactivate
$ python --version
Python 2.7.5
$
```
